using B.S.Data.MES.API.Applications.AccountApplication.Command;
using B.S.Data.MES.API.Applications.approve.Command;
using B.S.Data.MES.API.Applications.BaseData.Command.BOMCommand;
using B.S.Data.MES.API.Applications.BaseData.Command.ChanXIanCommand;
using B.S.Data.MES.API.Applications.BaseData.Command.CheJianCommand;
using B.S.Data.MES.API.Applications.BaseData.Command.CustomerCommand;
// 在文件顶部的using部分添加以下引用
using B.S.Data.MES.API.Applications.BaseData.Command.MaterialGroupCommand;
// 在文件顶部的using部分添加以下引用
using B.S.Data.MES.API.Applications.BaseData.Command.MaterialGroupCommand;
using B.S.Data.MES.API.Applications.BaseData.Command.MaterialTypeCommand;
using B.S.Data.MES.API.Applications.BaseData.Command.ProductMaterialCommand;
using B.S.Data.MES.API.Applications.BaseData.Command.SupplierCommand;
using B.S.Data.MES.API.Applications.BaseData.CommandHandlers.BOMCommandHandlers;
using B.S.Data.MES.API.Applications.CangKu.Command;
using B.S.Data.MES.API.Applications.GanttchartApplication.Command;
using B.S.Data.MES.API.Applications.Management.SteamApplication.Command.DeptTreeCommand;
using B.S.Data.MES.API.Applications.Management.SteamApplication.Command.FactoryCommand;
using B.S.Data.MES.API.Applications.Management.SteamApplication.Command.LoginLoggerCommand;
using B.S.Data.MES.API.Applications.Management.SteamApplication.Command.OrcanCommand;
using B.S.Data.MES.API.Applications.Management.SteamApplication.Command.RoleCommand;
using B.S.Data.MES.API.Applications.OrcanApplication.Command;
using B.S.Data.MES.API.Applications.QualityManagement.ExamineDesignCommand.Commands;
using B.S.Data.MES.API.Applications.QualityManagement.ExamineMaterialsCommand.Commands;
using B.S.Data.MES.API.Applications.QualityManagement.ExamineMaterialsCommand.Commands;
using B.S.Data.MES.API.Applications.QualityManagement.ExamineProjectCommand.Commands;
using B.S.Data.MES.API.Applications.QualityManagement.ExamineTaskCommand.Commands;
using B.S.Data.MES.API.Applications.QualityManagement.ExamineTypeModel.Command;
using B.S.Data.MES.API.Applications.WorkOrderManagement.Commands;
using B.S.Data.MES.API.Dto.CangKuDTO;
using B.S.Data.MES.API.Dto.CangKuDTO;
using B.S.Data.MES.API.Dto.CangKuDTO;
using B.S.Data.MES.API.Dto.ChanxianDto;
using B.S.Data.MES.API.Dto.ExamineProjectDTO;
using B.S.Data.MES.API.Dto.LoginDTO;
using B.S.Data.MES.API.Dto.TreeDTo;
using B.S.Data.MES.API.Dto.WorkDtos;
using B.S.Domain;
using B.S.Domain.Accounts;
using B.S.Domain.BasicData.Factory_modeling.shop_management;
using B.S.Domain.BasicData.MaterialManagement.BOM;
using B.S.Domain.BasicData.MaterialManagement.Material_type;
using B.S.Domain.BasicData.MaterialManagement.MaterialGroups;
using B.S.Domain.BasicData.MaterialManagement.Product_material;
using B.S.Domain.BasicData.MaterialManagement.Product_material;
using B.S.Domain.BasicData.QualityManagement;
using B.S.Domain.BasicData.SupplierManagement;
using B.S.Domain.CangKu;
using B.S.Domain.Dto;
using B.S.Domain.Dto.EorkOrderDTO;
using B.S.Domain.Dto.EorkOrderDTO;
using B.S.Domain.Dto.WuLiaoDto;
using B.S.Domain.Node;
using B.S.Domain.Process.ProcessrouteName;
using B.S.Domain.Ticket;
using B.S.Domain.基础数据.客户管理;
using B.S.Infratrctrue;
using B.S.Requst;
using B.S.Requst;
using B.S.Requst;
using Dm;
using ERP.Domain;
using MediatR;
using MediatR;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using MiniExcelLibs;
using Newtonsoft.Json;
using NPOI.SS.UserModel;
using NPOI.XSSF.Streaming;
using NPOI.XSSF.UserModel;
using System.IO;
using System.Security.Claims;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;

namespace B.S.Data.MES.API.Controllers
{
    /// <summary>
    /// 读的控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class ReadController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly IBaseRepository<CangKuQU> cangQRepository;
        private readonly IBaseRepository<ChuWei> chuRepository;
        private readonly IBaseRepository<Supplier> supplierRepository;
        private readonly ILogger<ReadController> logger;
        private readonly IHttpClientFactory _httpClientFactory;
        private readonly IBaseRepository<shop_management> shopRepository;
    
        public IBaseRepository<CangKuinfo> CangRepository { get; }
    
        public ReadController(IMediator mediator, 
                             ILogger<ReadController> logger, 
                             IHttpClientFactory httpClientFactory, 
                             IBaseRepository<CangKuinfo> CangRepository, 
                             IBaseRepository<CangKuQU> CangQRepository, 
                             IBaseRepository<ChuWei> chuRepository, 
                             IBaseRepository<Supplier> supplierRepository,
                             IBaseRepository<shop_management> shopRepository)
        {
            this.mediator = mediator;
            this.logger = logger;
            _httpClientFactory = httpClientFactory;
            this.CangRepository = CangRepository;
            cangQRepository = CangQRepository;
            this.chuRepository = chuRepository;
            this.supplierRepository = supplierRepository;
            this.shopRepository = shopRepository;
        }
        /// <summary>
        /// 车间
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIRequst<APIPageing<List<shop_management>>>> ListCheJian([FromQuery] ListChejianCommand command)
        {
            ListChejianCommand list = new ListChejianCommand();
            list.PageSize = command.PageSize;
            list.describe = command.describe;
            list.UpdateTime = command.UpdateTime;
            list.CreateTime = command.CreateTime;
            list.CreateName = command.CreateName;
            list.Workshopcoding = command.Workshopcoding;
            list.Workshopname = command.Workshopname;
            list.Pageindex = command.Pageindex;
            return mediator.Send(list);
        }
        /// <summary>
        /// 用户管理
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<APIRequst<APIPageing<List<AccountDTO>>>> GetAccount([FromQuery] AccountQueryCommand request)
        {
            return await mediator.Send(request);


        }
        /// <summary>
        /// 工厂信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIRequst<List<FactoryClass>>> FactorySelect([FromQuery] FactorySelectCommand request)
        {
            logger.LogInformation("获取工厂信息成功");
            return await mediator.Send(request);
        }
        /// <summary>
        /// 组织框架
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIRequst<List<OrcanClass>>> OrcanSelect([FromQuery] OrcandSelectCommand request)
        {
            logger.LogInformation("获取组织框架信息成功");
            return await mediator.Send(request);
        }
        [HttpGet]
        public async Task<APIRequst<APIPageing<List<RoleEntty>>>> RoleQuery([FromQuery] RoleQueryCommand request)
        {
            logger.LogInformation("获取角色信息成功");
            return await mediator.Send(request);

        }
        /// <summary>
        /// 获取登录日志信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIRequst<APIPageing<List<LoginLogger>>>> LoginLogger([FromQuery] LoginLoggerCommand request)
        {
            logger.LogInformation("获取登录日志信息成功");
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取组织框架信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIRequst<APIPageing<List<OrcantTreesDTO>>>> OrcanQuery([FromQuery] OrcanQueryCommand request)
        {
            logger.LogInformation("获取登录日志信息成功");
            return await mediator.Send(request);
        }
        [HttpGet]
        public async Task<APIRequst<List<TreeDTOs>>> DeptTree([FromQuery] DeptTreesCommand request)
        {
            logger.LogInformation("获取部门级联信息成功");
            return await mediator.Send(request);

        }
        /// <summary>
        /// 获取检验类型信息+条件查询
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回相应的任务</returns>
        [HttpGet]
        public Task<APIRequst<APIPageing<List<ExamineType>>>> GetExamineType([FromQuery] GetExamineTypeCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 工厂信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIRequst<APIPageing<List<FactoryClass>>>> FatoryQuery([FromQuery] FactoryQueryCommand request)
        {
            logger.LogInformation("获取工厂信息成功");
            return await mediator.Send(request);
        }
        /// <summary>
        /// 查询检验类型信息
        /// </summary>
        /// <returns>返回命令</returns>
        [HttpGet]
        public Task<APIRequst<List<ExamineType>>> ShowExamineType()
        {
            return mediator.Send(new GetQueryTypeCommand());
        }
        /// <summary>
        /// 条件查询+分页+获取检验项目信息
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIRequst<APIPageing<List<ProjectDTO>>>> GetExamineProject([FromQuery] GetExamineProjectCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 获取客户列表(分页)
        /// </summary>
        /// <param name="command">查询命令，包含页码和页大小</param>
        /// <returns>客户列表分页数据</returns>
        [HttpGet]
        public Task<APIRequst<APIPageing<List<client>>>> GetCustomerList([FromQuery] ListCustomerCommand command)
        {
            ListCustomerCommand listCommand = new ListCustomerCommand();
            listCommand.PageIndex = command.PageIndex;
            listCommand.PageSize = command.PageSize;
            return mediator.Send(listCommand);
        }

        /// <summary>
        /// 获取产线列表(分页)
        /// </summary>
        /// <param name="command">查询命令，包含页码和页大小</param>
        /// <returns>产线列表分页数据</returns>
        [HttpGet]
        public Task<APIRequst<APIPageing<List<ChanXianDto>>>> GetProductionLineList([FromQuery] ListChanXianCommand command)
        {
            ListChanXianCommand listCommand = new ListChanXianCommand();
            listCommand.Pageindex = command.Pageindex;
            listCommand.PageSize = command.PageSize;
            return mediator.Send(listCommand);
        }
        /// <summary>
        /// 获取所有车间信息（不分页）
        /// </summary>
        /// <returns>返回所有车间信息列表</returns>
        [HttpGet]
        public Task<APIRequst<List<shop_management>>> ShowCheJian()
        {
            return mediator.Send(new GetQueryChejianCommand());
        }
        [HttpGet]
        public async Task<IActionResult> ReadERP()
        {
            var http = _httpClientFactory.CreateClient();
            http.BaseAddress = new Uri("http://localhost:5199/");
            var reposo = http.GetAsync(requestUri: "/api/DingDan/QueryDingDan").Result;
            reposo.EnsureSuccessStatusCode();
            string responseData = await reposo.Content.ReadAsStringAsync();
            return Ok(responseData);
            //try
            //{
            //    var http = _httpClientFactory.CreateClient();
            //    http.BaseAddress = new Uri("http://localhost:5199/");
            //    var reposo =  http.GetAsync("/api/DingDan/QueryDingDan").Result;
            //    var repoContent =  reposo.Content.ReadAsStringAsync().Result;
            //    var list = JsonConvert.DeserializeObject<List<DingDan>>(repoContent);
            //    foreach (var dingDan in list)
            //    {
            //        // 假设 clientRepository.Add 接受单个 DingDan 对象
            //        _cilentRepository.Add(dingDan);
            //    }
            //    return Ok();
            //}
            //catch (HttpRequestException ex)
            //{

            //    return Problem($"调用远程API失败：{ex.Message}");
            //}
            //catch (JsonException ex)
            //{

            //    return Problem($"JSON反序列化失败：{ex.Message}");
            //}
            //catch ( Exception ex)
            //{
            //    return Problem($"未知错误：{ex.Message}");
            //}

        }
        /// <summary>
        /// 获取物料群组列表(分页)
        /// </summary>
        /// <param name="command">查询命令，包含页码和页大小</param>
        /// <returns>物料群组列表分页数据</returns>
        [HttpGet]
        public Task<APIRequst<APIPageing<List<GropDto>>>> GetMaterialGroupLivst([FromQuery] QueryMaterialGroupCommand command)
        {
            QueryMaterialGroupCommand listCommand = new QueryMaterialGroupCommand();
            listCommand.Pageindex = command.Pageindex;
            listCommand.PageSize = command.PageSize;
            return mediator.Send(listCommand);
        }
        /// <summary>
        /// 获取所有物料类型（用于下拉框）
        /// </summary>
        /// <param name="command">查询命令，可选择提供搜索条件</param>
        /// <returns>物料类型列表</returns>
        [HttpGet]
        public Task<APIRequst<List<Material_type>>> GetAllMaterialTypes()
        {
            return mediator.Send(new QueryMaterialTypeCommand());
        }

        /// <summary>
        /// 获取所有工艺路线（用于下拉框）
        /// </summary>
        /// <returns>工艺路线列表</returns>
        [HttpGet]
        public Task<APIRequst<List<Processroute>>> GetAllProcessroutes()
        {
            return mediator.Send(new GetAllProcessrouteCommand());
        }
        [HttpGet]
        public async Task<APIRequst<List<TreeDTOs>>> TreeGet([FromQuery] TreeQueryCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取产品物料列表(四表联查增强版)
        /// </summary>
        /// <param name="query">查询命令，包含页码和页大小</param>
        /// <returns>产品物料列表分页数据，包含关联的物料群组、物料类型和工艺路线完整信息</returns>
        [HttpGet]
        public async Task<APIRequst<APIPageing<List<ProductMaterialDto>>>> GetProductMaterialListWithJoins([FromQuery] QueryProductMaterialCommand query)
        {
            QueryProductMaterialCommand command = new QueryProductMaterialCommand();
            command.PageSize = query.PageSize;
            command.Pageindex = query.Pageindex;
            return await mediator.Send(command);
        }
        [HttpGet]
        public async Task<APIRequst<List<Material_group>>> GetGroupSelect()
        {
            return await mediator.Send(new GetAllMaterialGroupsCommand());
        }
        /// <summary>
        /// 获取检验方案的信息
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public async Task<APIRequst<APIPageing<List<ExamineDesign>>>> GetExaminDesign([FromQuery] GetExamineDesignCommand command)
        {
            //  HttpClient client = new HttpClient();

            //  client.BaseAddress = new Uri("http://localhost:5199");
            //  var path = client.GetAsync("/api/DingDan/QueryDingDan").Result;
            //  path.EnsureSuccessStatusCode();

            //  var responseData = await path.Content.ReadAsStringAsync();
            //var str=  JsonConvert.DeserializeObject<List<DingDan>>(responseData);

            return await mediator.Send(command);
        }
        /// <summary> 
        /// 获取检验方案的信息
        /// </summary>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIRequst<List<ExamineDesign>>> ShowExaminDesign()
        {
            return mediator.Send(new ShowExamineDesignCommand());
        }
        /// <summary>
        /// 获取检验任务信息+条件查询
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回相应的任务</returns>
        [HttpGet]
        public Task<APIRequst<APIPageing<List<ExamineTask>>>> GetExamineTask([FromQuery] GetExamineTaskCommand command)
        {
            return mediator.Send(command);
        }
        [HttpGet]
        public Task<APIRequst<List<BOMDTO>>> GetBom()
        {
            return mediator.Send(new QueryBOMWithRelatedTablesCommand());
        }
        /// <summary>
        /// 获取产品物料
        /// </summary>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIRequst<List<Product_material>>> ShowProduct()
        {
            return mediator.Send(new ShowProduct_materialCommand());
        }
        /// <summary>
        /// 获取来料检验信息+条件查询
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回相应的任务</returns>
        [HttpGet]
        public Task<APIRequst<APIPageing<List<MaterialsExamine>>>> GetExamineMater([FromQuery] GetExamineMaterisonlCommand command)
        {
            return mediator.Send(command);
        }
        [HttpGet]
        public Task<APIRequst<List<GropDto>>> GropWithType()
        {

            return mediator.Send(new GetAllMaterialGroupsWithTypeCommand());
        }
        [HttpGet]
        public Task<APIRequst<List<GropDto>>> GetMaterialGroupsWithType([FromQuery] GetMaterialGroupsWithTypeCommand query)
        {
            GetMaterialGroupsWithTypeCommand command = new GetMaterialGroupsWithTypeCommand();
            command.Materialtypeid = query.Materialtypeid;
            return mediator.Send(command);
        }
        [HttpGet]
        public Task<APIRequst<APIPageing<List<CangKuQUWithCangKuDTO>>>> GetCangKuQU([FromQuery] GetCangKuQUPagedCommand query)
        {
            GetCangKuQUPagedCommand command = new GetCangKuQUPagedCommand();
            command.PageSize = query.PageSize;
            command.PageIndex = query.PageIndex;
            command.CangkuNo = query.CangkuNo;
            command.CangName = query.CangName;
            return mediator.Send(command);
        }
        [HttpGet]
        public Task<APIRequst<APIPageing<List<CangKuDTO>>>> ShowCangku([FromQuery] GetCangKuPagedCommand query)
        {
            GetCangKuPagedCommand command = new GetCangKuPagedCommand();
            command.PageSize = query.PageSize;
            command.CangkuNo = query.CangkuNo;
            command.CangName = query.CangName;
            command.PageIndex = query.PageIndex;
            command.PageSize = query.PageSize;
            command.CangTypeId = query.CangTypeId;
            command.Role = query.Role;
            return mediator.Send(command);
        }
        [HttpGet]
        public async Task<APIRequst<List<CangTypeinfo>>> GetAllCangType()
        {
            return await mediator.Send(new GetAllCangTypeCommand());
        }
        [HttpGet]
        public Task<APIRequst<List<CangKuinfo>>> GetCangku()
        {
            return mediator.Send(new GetAllCangkuCommand());
        }
        /// <summary>
        /// 获取成品检验一条
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public IActionResult GetExcl()
        {

            IWorkbook workbook = new XSSFWorkbook();
            ISheet s = workbook.CreateSheet("仓库信息表");
            IRow r = s.CreateRow(0);
            r.CreateCell(0).SetCellValue("编码");
            r.CreateCell(1).SetCellValue("名称");
            r.CreateCell(2).SetCellValue("类型");
            r.CreateCell(3).SetCellValue("管理员");
            r.CreateCell(4).SetCellValue("地址");
            r.CreateCell(5).SetCellValue("描述");


            var su = CangRepository.GetAll();
            int i = 1;
            foreach (var item in su.ToList())
            {
                IRow rs = s.CreateRow(i);
                rs.CreateCell(0).SetCellValue(item.CangkuNo);
                rs.CreateCell(1).SetCellValue(item.CangName);
                rs.CreateCell(2).SetCellValue(item.CangTypeId);
                rs.CreateCell(3).SetCellValue(item.Role);
                rs.CreateCell(4).SetCellValue(item.Address);
                rs.CreateCell(5).SetCellValue(item.MShu);
                i++;

            }
            byte[] bs = null;
            using (MemoryStream str = new MemoryStream())
            {
                workbook.Write(str);

                bs = str.ToArray();
            }

            var mime = new FileExtensionContentTypeProvider().Mappings[".xlsx"];
            return File(bs, mime, "仓库表");



        }
        [HttpGet]
        public IActionResult DOWExcel()
        {
            var list = cangQRepository.GetAll().ToList();
            var stream = new MemoryStream();
            stream.SaveAs(list);
            stream.Seek(0, SeekOrigin.Begin);
            var mui = new FileExtensionContentTypeProvider().Mappings[".xlsx"];
            return new FileStreamResult(stream, mui)
            {
                FileDownloadName = "库位信息表.xlsx"
            };


        }
        /// <summary>
        /// 获取储位与仓库区域关联信息（两表联查）
        /// </summary>
        /// <returns>储位与仓库区域关联信息列表</returns>
        [HttpGet]
        public Task<APIRequst<APIPageing<List<ChuWeiWithCangKuQUDTO>>>> GetChuWeiWithCangKuQU([FromQuery] GetChuWeiWithCangKuQUCommand chuwei)
        {
            GetChuWeiWithCangKuQUCommand command = new GetChuWeiWithCangKuQUCommand();
            command.Pageindex = chuwei.Pageindex;
            command.PageSize = chuwei.PageSize;
            return mediator.Send(command);
        }
        [HttpGet]
        public Task<APIRequst<List<CangKuQU>>> GetCangKuquList() // 修改方法名，避免路由冲突
        {
            return mediator.Send(new GetCuQuCommand());
        }
        [HttpGet]
        public IActionResult ChuExcel()
        {
            var list = chuRepository.GetAll().ToList();
            var strem = new MemoryStream();
            strem.SaveAs(list);
            strem.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(strem, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = "储位设置.xlsx"
            };
        }
        [HttpGet]
        public async Task<APIRequst<List<WorkOrderDTOs>>> WorkOrderQuery([FromQuery] WorkOrderQueryCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 展示产品物料信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Task<APIRequst<List<Product_material>>> GetProductMaterial()
        {
            return mediator.Send(new ShowProductMaterialCommand());
        }
        /// <summary>
        /// 获取所有审批表数据
        /// </summary>
        /// <returns>审批表数据列表</returns>
        [HttpGet]
        public Task<APIRequst<List<ShenPiinfo>>> GetAllShenPi([FromQuery] GetAllShenPiCommand query)
        {
            query.UserId = int.Parse(User.FindFirstValue("UserId"));
            return mediator.Send(query);
        }
        [HttpGet]
        public Task<APIRequst<WorkOrder>> GetWorkOrderById(int workId)
        {
            GetWorkOrderByIdCommand command = new GetWorkOrderByIdCommand();
            command.WorkId = workId;
            return mediator.Send(command);
        }
        [HttpGet]
        public Task<APIRequst<List<WorkOrder>>> GetAllWorkOrders()
        {
            return mediator.Send(new GetAllWorkOrdersCommand());
        }
        /// <summary>
        /// 展示BOM信息
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIRequst<List<BOM>>> ShowBom([FromQuery] GetBomCommand command)
        {
            return mediator.Send(command);
        }
        [HttpGet]
        public Task<APIRequst<List<RukuinfoLog>>> ShowRuku()    
        {
            return mediator.Send(new GetAllRukuLogCommand());
        }
        /// <summary>
        /// 根据仓库ID获取库位列表（用于三级联动）
        /// </summary>
        /// <param name="cangId">仓库ID</param>
        /// <returns>库位列表</returns>
        [HttpGet]
        public Task<APIRequst<List<CangKuQU>>> GetKuWeiByCangId(int cangId)
        {
            var command = new GetKuWeiByCangIdCommand { CangId = cangId };
            return mediator.Send(command);
        }

        /// <summary>
        /// 根据库位ID获取储位列表（用于三级联动）
        /// </summary>
        /// <param name="kuWeiId">库位ID</param>
        /// <returns>储位列表</returns>
        [HttpGet]
        public Task<APIRequst<List<ChuWei>>> GetChuWeiByKuWeiId(int kuWeiId)
        {
            var command = new GetChuWeiByKuWeiIdCommand { KuWeiId = kuWeiId };
            return mediator.Send(command);
        }

        /// <summary>
        /// 获取所有仓库列表（用于三级联动的第一级）
        /// </summary>
        /// <returns>仓库列表</returns>
        [HttpGet]
        public Task<APIRequst<List<CangKuinfo>>> GetAllCangKuForLinkage()
        {
            return mediator.Send(new GetAllCangkuCommand());
        }


        /// <summary>
        /// 获取入库与仓库、库位、储位关联信息（四表联查）
        /// </summary>
        /// <param name="command">包含查询条件和分页信息的命令对象</param>
        /// <returns>包含分页数据的API响应</returns>

    
/// <summary>
/// 获取供应商列表(分页)
/// </summary>
/// <param name="command">查询命令，包含页码和页大小</param>
/// <returns>供应商列表分页数据</returns>
[HttpGet]
public Task<APIRequst<APIPageing<List<Supplier>>>> GetSupplierList([FromQuery] ListSupplierCommand command)
{
    ListSupplierCommand listCommand = new ListSupplierCommand();
    listCommand.PageIndex = command.PageIndex;
    listCommand.PageSize = command.PageSize;
    return mediator.Send(listCommand);
}
[HttpGet]
public Task<APIRequst<List<Finished_ProductTest>>> GetAllFinishedProducts()
{
    // 创建查询命令
    GetAllFinishedProductsCommand command = new GetAllFinishedProductsCommand();
    // 发送命令到MediatR处理器
    return mediator.Send(command);
}
        [HttpGet]
        [AllowAnonymous]
        public async Task<APIRequst<List<RoleEntty>>> GetRoleListForDropdown()
        {
            // 创建获取角色列表的命令
            var command = new GetRoleListCommand();
            // 使用中介者模式发送命令并返回结果
            return await mediator.Send(command);
        }
        [HttpGet]
        public Task<APIRequst<List<FenPeiDto>>> ShowFenPei() 
        {
            return mediator.Send(new GetFenpeiCommand());
        }
        [HttpGet]
        public IActionResult DowGongYing() 
        {
             var list=supplierRepository.GetAll().ToList();
            var stream = new MemoryStream();
            stream.SaveAs(list);
            stream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = "供应商信息表.xlsx"
            };
        }
        [HttpGet]
        public Task<APIRequst<List<Tel>>> GetAllTel()
        {
            return mediator.Send(new GetAllTelCommand());
        }
        [HttpGet]
        public IActionResult DowCheJian()
        {
            // 获取所有车间管理数据
            var list = shopRepository.GetAll().ToList();

            // 创建内存流用于存储Excel文件
            var stream = new MemoryStream();

            // 使用MiniExcelLibs将数据保存到内存流
            stream.SaveAs(list);

            // 将流的位置设置为开始
            stream.Seek(0, SeekOrigin.Begin);

            // 返回文件流结果，设置文件下载名称
            return new FileStreamResult(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = "车间管理信息表.xlsx"
            };
        }
    }
}

/// <summary>
/// 导出车间管理数据到Excel
/// </summary>
/// <returns>包含车间管理数据的Excel文件</returns>



